package fts.ftsmonitoring;


/**
 * @author Igor Zilberman (304033327)
 * FileMonitoringRoot represents a root to monitor by the IFileMonitoringService
 * 
 */
public class FileMonitoringRoot {
	private String rootPath;
	private String fileExp;
	
	/**
	 * @param rootPath Root path to monitor
	 * @param filePatterns Array of file patterns to monitor (wildcard expressions e.g. "*.*", "*.jpg", "a?.ja?a")
	 */
	public FileMonitoringRoot(String rootPath, String[] filePatterns)
	{
		if(null == rootPath || rootPath.length() == 0)
		{
			throw new IllegalArgumentException("rootPath");
		}
		if(null == filePatterns || filePatterns.length == 0)
		{
			throw new IllegalArgumentException("filePatterns");
		}
		this.rootPath = rootPath;
		
    	StringBuilder exprBld = new StringBuilder();
    	for(String pat:filePatterns)
    	{
    		exprBld.append("|").append(pat);
    	}
    	String expr = exprBld.length() == 0 ? ".*" : ("(" + exprBld.toString().substring(1).replace("\\", "\\\\").replace("(", "\\(").replace("[", "\\[").replace(".", "\\.").replace("*", ".*").replace("?", ".") + ")");
    	fileExp = "(?i:" + new String(expr.toLowerCase()) + ")";

	}
	
	
	/**
	 * @return Root path
	 */
	public String getRootPath()
	{
		return rootPath;
	}
	
	/**
	 * @return Regular expression representation of filename wildcards
	 */
	public String getFilePatternsExpression()
	{
		return fileExp;
	}
}
